package com.example.thirdstage_project.controller;

import com.example.thirdstage_project.common.Code;
import com.example.thirdstage_project.common.Result;
import com.example.thirdstage_project.entity.Project;
import com.example.thirdstage_project.entity.ProjectCategory;
import com.example.thirdstage_project.ov.ProjectCategoryExpertOV;
import com.example.thirdstage_project.service.ProjectCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 86158
 * @version 1.0
 * Create by 2022/11/28 21:06
 */

/**
 * 项目管理里面的项目查询
 */



@RestController
@RequestMapping("/projectcategorys")
public class ProjectCategoryController {



    @Autowired
    private ProjectCategoryService projectCategoryService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public Result selectAll(){
        List<ProjectCategoryExpertOV> list = projectCategoryService.select();
        Integer code = list != null ? Code.GET_OK : Code.GET_ERR;
        String msg = list != null ? "" : "数据查询失败";
        return new Result(code,list,msg);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        boolean delete = projectCategoryService.removeById(id);
        return new Result(delete ? Code.DELETE_OK : Code.DELETE_ERR,delete);
    }

    /**
     * 查询项目管理四个信息
     */
    @GetMapping("/selectFour")
    public Result select(){
        List<ProjectCategoryExpertOV> list = projectCategoryService.selectFour();
        Integer code = list != null ? Code.GET_OK : Code.GET_ERR;
        String msg = list != null ? "" : "数据查询失败";
        return new Result(code,list,msg);
    }

    /**
     * 按照id查询
     */
    @GetMapping("/selectById")
    public Result selectById(int categoryid){
        List<ProjectCategory> list = projectCategoryService.selectByPid(categoryid);
        Integer code = list != null ? Code.GET_OK : Code.GET_ERR;
        String msg = list != null ? "" : "数据查询失败";
        return new Result(code,list,msg);
    }
/**
 * 更新
 *
 */
    @PostMapping("/post")
    public Result update(Project project ){
        boolean save = projectCategoryService.updateProject(project);
        return new Result(save ? Code.UPDATE_OK : Code.UPDATE_ERR,save);
    }

    @PostMapping("/project")
    public Result updateProject(ProjectCategory project){
        boolean save = projectCategoryService.updatePro(project);
        return new Result(save ? Code.UPDATE_OK : Code.UPDATE_ERR,save);
    }
}
